package controller1;/*
package com.wuchao.controller;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;
import java.io.IOException;

*/
/**
 * @Author wuchao66
 * @Date 2022/7/8 10:22
 * @Version 1.0
 *//*

@WebFilter(filterName = "FilterUtf8",urlPatterns = "/*",
initParams = {@WebInitParam(name = "encode",value = "utf-8")})
public class FilterUtf8 implements Filter {
    //定义一个初始化的编码规则--全局可拔插工具类
    private String encode;
    public void destroy() {//摧毁
        this.encode=null;
    }
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        String encode = req.getCharacterEncoding();//拿到拦截的请求的编码规则
        if(encode==null||!encode.equals(this.encode)){
            req.setCharacterEncoding(this.encode);//不满足就挂上标准
        }
        chain.doFilter(req, resp);//调用 链式操作 放行
    }
    public void init(FilterConfig config) throws ServletException {//初始化
            //拿到今天要过滤的标准
        String encode = config.getInitParameter("encode");
        //挂到今天的标准初始化
        this.encode=encode;
    }
}
*/
